import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;

public class LC_145 {

    public List<Integer> postorderTraversal(LC_144.TreeNode root) {
        List<Integer> list = new ArrayList<>();
        Stack<LC_144.TreeNode> stack = new Stack<>();
        stack.push(root);
        while(!stack.empty()){
            LC_144.TreeNode node = stack.pop();;
            if(node != null){
                list.add(node.val);
            }else{
                continue;
            }
            stack.push(node.left);
            stack.push(node.right);
        }
        Collections.reverse(list);
        return list;
    }
}
